<template>
	<view class="profile-container">
		<view class="profile-header">
			<view class="avatar-section">
				<view class="avatar-wrapper" @click="chooseAvatar">
					<image :src="userInfo.avatar || '/static/images/avatar.png'" class="avatar"></image>
					<view class="avatar-edit-icon">
						<u-icon name="camera" color="#fff" :size="20"></u-icon>
					</view>
				</view>
				<text class="avatar-tip">点击更换头像</text>
			</view>
		</view>
		
		<view class="profile-form">
			<view class="form-item">
				<view class="form-label">昵称</view>
				<view class="form-input-wrapper">
					<input 
						class="form-input" 
						v-model="userInfo.nickname" 
						placeholder="请输入昵称"
						maxlength="20"
					/>
					<u-icon name="arrow-right" color="#999" :size="16"></u-icon>
				</view>
			</view>
			
			<view class="form-item">
				<view class="form-label">手机号</view>
				<view class="form-input-wrapper">
					<text class="form-text">{{userInfo.phone || '未绑定'}}</text>
					<u-icon name="arrow-right" color="#999" :size="16"></u-icon>
				</view>
			</view>
			
			<!-- 性别选择器 -->
			<picker 
				:range="genderOptions" 
				@change="onGenderConfirm"
			>
				<view class="form-item">
					<view class="form-label">性别</view>
					<view class="form-input-wrapper">
						<text class="form-text">{{genderText}}</text>
						<u-icon name="arrow-right" color="#999" :size="16"></u-icon>
					</view>
				</view>
			</picker>
			
			<!-- 日期选择器 -->
			<picker 
				mode="date" 
				:value="userInfo.birthday" 
				@change="onDateConfirm"
			>
				<view class="form-item">
					<view class="form-label">生日</view>
					<view class="form-input-wrapper">
						<text class="form-text">{{userInfo.birthday || '请选择生日'}}</text>
						<u-icon name="arrow-right" color="#999" :size="16"></u-icon>
					</view>
				</view>
			</picker>
			
			<view class="form-item" style="align-items: flex-start;">
				<view class="form-label" style="width: 130rpx; border: 1px solid red;">个性签名</view>
				<view class="form-input-wrapper">
					<textarea 
						class="form-textarea" 
						v-model="userInfo.signature" 
						placeholder="请输入个性签名"
						maxlength="50"
					></textarea>
					<u-icon name="arrow-right" color="#999" :size="16"></u-icon>
				</view>
			</view>
		</view>
		
		<view class="profile-actions">
			<button class="save-btn" @click="saveProfile">保存修改</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					avatar: '',
					nickname: '用户昵称',
					phone: '138****8888',
					gender: 1,
					birthday: '',
					signature: '这个人很懒，什么都没留下~'
				},
				genderOptions: ['男', '女', '保密']
			}
		},
		computed: {
			genderText() {
				const genderMap = {
					0: '保密',
					1: '男', 
					2: '女'
				}
				return genderMap[this.userInfo.gender] || '保密'
			}
		},
		onLoad() {
			// 这里可以加载用户信息
			this.loadUserInfo()
		},
		methods: {
			loadUserInfo() {
				// 模拟加载用户信息
				console.log('this.vuex_user',this.vuex_user);
				this.userInfo = {
					avatar: this.vuex_user?.user_avatar || '/static/images/avatar.png',
					nickname: this.vuex_user?.user_nickname || '用户昵称',
					phone: this.vuex_user?.user_mobile || '138****8888',
					gender: 1,
					birthday: '',
					signature: '这个人很懒，什么都没留下~'
				}
			},
			
			chooseAvatar() {
				uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['album', 'camera'],
					success: (res) => {
						this.userInfo.avatar = res.tempFilePaths[0]
						uni.showToast({
							title: '头像已选择',
							icon: 'success'
						})
					}
				})
			},
			
			onGenderConfirm(e) {
				const genderMap = {
					'男': 1,
					'女': 2,
					'保密': 0
				}
				const selectedGender = this.genderOptions[e.detail.value]
				this.userInfo.gender = genderMap[selectedGender]
			},
			
			onDateConfirm(e) {
				this.userInfo.birthday = e.detail.value
			},
			
			saveProfile() {
				// 这里可以调用保存接口
				uni.showLoading({
					title: '保存中...'
				})
				
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						title: '保存成功',
						icon: 'success'
					})
					
					// 返回上一页
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
				}, 1000)
			}
		}
	}
</script>

<style scoped>
	.profile-container {
		min-height: 100vh;
		background-color: #f5f5f5;
	}
	
	.profile-header {
		background-color: #fff;
		padding: 40rpx 30rpx;
		margin-bottom: 20rpx;
	}
	
	.avatar-section {
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.avatar-wrapper {
		position: relative;
		margin-bottom: 20rpx;
	}
	
	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		border: 4rpx solid #f0f0f0;
	}
	
	.avatar-edit-icon {
		position: absolute;
		right: 0;
		bottom: 0;
		width: 40rpx;
		height: 40rpx;
		background-color: #36be6a;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 4rpx solid #fff;
	}
	
	.avatar-tip {
		font-size: 24rpx;
		color: #999;
	}
	
	.profile-form {
		background-color: #fff;
	}
	
	.form-item {
		display: flex;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #f0f0f0;
	}
	
	.form-item:last-child {
		border-bottom: none;
	}
	
	.form-label {
		width: 160rpx;
		font-size: 28rpx;
		color: #333;
		font-weight: 500;
		flex-shrink: 0;
	}
	
	.form-input-wrapper {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	
	.form-input {
		flex: 1;
		font-size: 28rpx;
		color: #333;
		text-align: right;
		padding-right: 20rpx;
	}
	
	.form-text {
		flex: 1;
		font-size: 28rpx;
		color: #333;
		text-align: right;
		padding-right: 20rpx;
	}
	
	.form-textarea {
		flex: 1;
		font-size: 28rpx;
		color: #333;
		text-align: right;
		padding-right: 20rpx;
		min-height: 60rpx;
		line-height: 1.5;
	}
	
	.profile-actions {
		padding: 40rpx 30rpx;
	}
	
	.save-btn {
		width: 100%;
		height: 88rpx;
		background-color: #36be6a;
		color: #fff;
		font-size: 32rpx;
		border-radius: 44rpx;
		border: none;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.save-btn:active {
		background-color: #2ea55a;
	}
</style> 